package com.volunteer_sys.Controller;

import com.volunteer_sys.Utils.RedisUtils;
import com.volunteer_sys.pojo.Activity;
import com.volunteer_sys.service.AttService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminControllor {
    @Autowired
    AttService attService;

    @Autowired
    RedisUtils redisUtils;

    @RequestMapping (value = "/creatActivity",method = RequestMethod.POST)
    @ResponseBody
    public String creatActivities(@RequestBody Activity att){
        if(attService.addAtt(att))
        {
            System.out.println("添加"+att.getName()+"成功");
            return "添加成功";
        }
            else return "添加失败";
    }
    @RequestMapping (value = "/delActivity",method = RequestMethod.POST)
    @ResponseBody
    public String creatActivities(@Param(value = "id") Integer id){
        if(attService.delAtt(id))
        {
            return "成功";
        }
        else return "失败";
    }

    @RequestMapping (value = "/openSignature",method = RequestMethod.POST)
    @ResponseBody
    public String openSignature(@Param(value = "id")Integer id){
        if(attService.openSignature(id))
        {
            return "成功";
        }
        else return "失败";
    }

    @RequestMapping (value = "/cancelSignature",method = RequestMethod.POST)
    @ResponseBody
    public String cancelSignature(@Param(value = "id")Integer id){
        if(attService.cancelSignature(id))
        {
            return "成功";
        }
        else return "失败";
    }

    @RequestMapping (value = "/getAllActivities",method = RequestMethod.POST)
    @ResponseBody
    public List<Activity> getAllActivities(){
        return attService.getAllAtt();
    }

    @RequestMapping (value = "/getActivity",method = RequestMethod.POST)
    @ResponseBody
    public Activity getActivity(@Param(value = "id")Integer id){
        return attService.getAtt(id);
    }

    @RequestMapping (value = "/Signup",method = RequestMethod.POST)
    @ResponseBody
    public String Signup(@Param(value = "att_id")Integer att_id,@Param(value = "stu_id")Integer stu_id){
        if(redisUtils.addStuCache(att_id,stu_id)){
            System.out.println("成功");
            System.out.println();
            return "成功";
        }else {
            System.out.println("失败");
            return "失败";
        }
    }

}
